package com.lxw.rmg.menu.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lxw.common.utils.PageUtils;
import com.lxw.common.utils.R;
import com.lxw.rmg.menu.entity.MenuEntity;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lxw.rmg.menu.entity.MatterEntity;
import com.lxw.rmg.menu.service.MatterService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * 物料库存表
 *
 * @author lxw
 * @email 
 * @date 2023-03-20 20:02:08
 */
@RestController
@RequestMapping("rmg/matter")
public class MatterController {
    @Autowired
    private MatterService matterService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("rmg:matter:list")
    public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){




        PageUtils page = matterService.queryPage(params);

        //获取参数
        String mateName = (String)params.get("mateName");
        if (!StringUtils.isNullOrEmpty(mateName) && !" ".equals(mateName)){
            List matterEntities = matterService.list(
                    new QueryWrapper<MatterEntity>().eq("mate_name", mateName));
            page.setList(matterEntities);
            page.setTotalCount(matterEntities.size());
        }


        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("rmg:matter:info")
    public R info(@PathVariable("id") Integer id){
		MatterEntity matter = matterService.getById(id);

        return R.ok().put("matter", matter);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("rmg:matter:save")
    public R save(@RequestBody MatterEntity matter){
        matter.setMateCode(UUID.randomUUID().toString());
		matterService.save(matter);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("rmg:matter:update")
    public R update(@RequestBody MatterEntity matter){

		matterService.updateById(matter);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("rmg:matter:delete")
    public R delete(@RequestBody Integer[] ids){
		matterService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
